package cloud.maque.module.system.controller;

import cloud.maque.common.core.response.R;
import cloud.maque.module.system.entity.SysPrivilege;
import cloud.maque.module.system.entity.SysRole;
import cloud.maque.module.system.extend.UserRoleExtendService;
import cloud.maque.module.system.service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色接口
 */
@Tag(name = "角色接口")
@RestController
@RequestMapping(value = "/role")
public class RoleController {


    @Autowired
    RoleService roleService;

    @Autowired
    UserRoleExtendService roleExtendService;

    @Operation(summary = "角色列表")
    @PostMapping("/list")
    public R<List<SysRole>> List(@RequestBody SysRole pageReq) {
        return R.ok("OK", roleService.GetList(pageReq));
    }

    @Operation(summary = "权限保存")
    @PostMapping("/save")
    public R<SysPrivilege> Save(@RequestBody SysRole data) {
        return R.ok("OK", roleService.SaveRole(data));
    }


    @Operation(summary = "权限删除")
    @DeleteMapping("/delete/{id}")
    public R<Boolean> Delete(@PathVariable("id") String id) {
        return R.ok("OK", roleExtendService.DeleteRole(id));
    }
}
